
import path from 'path'
import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import fullImportPlugin from "./src/plugins/fullImportPlugin";

const pathSrc = path.resolve(__dirname, 'src')

export default defineConfig(({ mode, command }) =>{
  const env = loadEnv(mode, process.cwd())
  let plugins=  [
      vue(),
      createSvgIconsPlugin({
          iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
          symbolId: 'icon-[dir]-[name]',
          svgoOptions: command === 'build'
      })
  ]
    if(env.VITE_NODE_ENV==='development'){
        plugins.push(fullImportPlugin())
    }else {
        plugins.push(AutoImport({
            resolvers: [ElementPlusResolver()],
        }))
        plugins.push( Components({
            resolvers: [ElementPlusResolver()],
        }))
    }
  return {
    server:{
      host: '0.0.0.0',
      proxy:{
        '/api': {
          target: 'http://10.10.2.72:8007',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, "")
        }
      }
    },
    plugins:plugins,
    css: {
      preprocessorOptions: {
        // 全局样式引入
        scss: {
          api: 'modern-compiler' ,
        }
      }
    },
    resolve: {
      alias: {
        '@': pathSrc,
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    }
  }

})
